package org.zanpu.metadataserver.core.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MD on 2016/11/3.
 */
public class ControllerUtilities {

    public String quotes = "\"";

    public String comma = ",";

    public String select = "SELECT * FROM ";

    /**
     * 将json格式字符串转化为map
     *
     * @param jsonStr
     * @return
     */
    public Map<String, Object> jsonStrToMap(String jsonStr) {
        Map<String, Object> jsonMap = new HashMap<>();
        Arrays.asList(jsonStr.split(",")).parallelStream().forEach(str-> {
            String key =str.split(":")[0], value = str.split(":")[1];
            jsonMap.put(key.replaceAll("\\{", "").replaceAll("\"", ""), value.contains("\"") ? value.replaceAll("}", "").replaceAll("\"", "") : Integer.parseInt(value.replaceAll("}", "")));
        });
        return jsonMap;
    }
}
